#include "history_show.h"
#include "ui_history_show.h"
static int i=0;
History_Show::History_Show(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::History_Show)
{
    ui->setupUi(this);
    qCustomPlot=new QCustomPlot(this);
    qCustomPlot->setGeometry(10,30,1200,600);
    QFont font("宋体",12,75);
    //QFont font_line("Microsoft YaHei",12,30);
    /**********************************
    *日历显示
    */
    date_lable=new QLabel(this);
    date_lable->setText(QObject::tr("日期:"));
    date_lable->setFont(font);
    date_lable->setGeometry(10,0,100,30);

    date_edit=new QDateEdit(QDate::currentDate() ,this);//表示默认为当天
    date_edit->setMinimumDate(QDate::currentDate().addDays(-30));//表示显示有效期最早为之前30天。
    date_edit->setMaximumDate(QDate::currentDate());//表示显示有效期最晚为今天。
    date_edit->setCalendarPopup(true);//以日历状态展示
    date_edit->setGeometry(150,0,150,30);
    date_edit->setFont(font);
    /*
    *姓名和床号的显示
    */

    Name_lable=new QLabel(this);
    Name_lable->setText(QObject::tr("姓名:"));
    Name_lable->setFont(font);
    Name_lable->setGeometry(350,0,100,30);

    Name_lineedit=new QLabel(this);
    Name_lineedit->setText(QObject::tr("liming"));
    Name_lineedit->setFont(font);
    Name_lineedit->setGeometry(470,0,100,30);

    room_lable=new QLabel(this);
    room_lable->setText(QObject::tr("床号:"));
    room_lable->setFont(font);
    room_lable->setGeometry(600,0,100,30);

    room_lineedit=new QLabel(this);
    room_lineedit->setText(QObject::tr("21-1-1-1"));
    room_lineedit->setFont(font);
    room_lineedit->setGeometry(720,0,100,30);

    this->setWindowTitle("历史曲线");
    //Pa_graph=new QCPGraph(CustomPlot);
    //Spend_graph=new QCPGraph(CustomPlot);
    Init_customplot(qCustomPlot);
    this->setFixedSize(1200,700);
}

History_Show::~History_Show()
{
    delete ui;
}

void History_Show::Init_customplot(QCustomPlot *CustomPlot)
{
    CustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
    QLinearGradient plotGradient;
    plotGradient.setStart ( 0, 0 );
    plotGradient.setFinalStop ( 0, 350 );
    plotGradient.setColorAt ( 0, QColor ( 80, 80, 80 ) );
    plotGradient.setColorAt ( 1, QColor ( 50,50, 50 ) );
    CustomPlot->setBackground ( plotGradient );//整个界面的背景色
    QLinearGradient axisRectGradient;
    axisRectGradient.setStart ( 0, 0 );
    axisRectGradient.setFinalStop ( 0, 350 );
    axisRectGradient.setColorAt ( 0, QColor ( 80, 80, 80 ) );
    axisRectGradient.setColorAt ( 1, QColor ( 30, 30, 30 ) );
    CustomPlot->axisRect()->setBackground ( axisRectGradient );//填充表格的背景色
    CustomPlot->xAxis->setBasePen ( QPen ( Qt::white, 1 ) );//坐标轴的颜色
    CustomPlot->yAxis->setBasePen ( QPen ( Qt::white, 1 ) );
    CustomPlot->xAxis->setTickPen ( QPen ( Qt::black, 1 ) );//坐标轴大格点底部颜色
    CustomPlot->yAxis->setTickPen ( QPen ( Qt::white, 1 ) );
    CustomPlot->xAxis->setSubTickPen ( QPen ( Qt::white, 1 ) );//坐标轴小格点底部颜色
    CustomPlot->yAxis->setSubTickPen ( QPen ( Qt::red, 1 ) );
    CustomPlot->xAxis->setTickLabelColor ( Qt::white );//坐标轴数据的颜色
    CustomPlot->yAxis->setTickLabelColor ( Qt::white );
    CustomPlot->xAxis->grid()->setPen ( QPen ( QColor ( 255, 0, 0 ), 1, Qt::DotLine ) );//大格点的网格颜色
    CustomPlot->yAxis->grid()->setPen ( QPen ( QColor ( 140, 140, 140 ), 1, Qt::DotLine ) );
    CustomPlot->xAxis->grid()->setSubGridPen ( QPen ( QColor ( 0, 0, 255 ), 1, Qt::DotLine ) );//小格点的网格颜色
    CustomPlot->yAxis->grid()->setSubGridPen ( QPen ( QColor ( 80, 80, 80 ), 1, Qt::DotLine ) );
    CustomPlot->xAxis->grid()->setSubGridVisible ( true );//是否有小格点的网格显示
    CustomPlot->yAxis->grid()->setSubGridVisible ( true );
    CustomPlot->xAxis->grid()->setZeroLinePen ( Qt::NoPen );
    CustomPlot->yAxis->grid()->setZeroLinePen ( Qt::NoPen );
    CustomPlot->xAxis->setUpperEnding ( QCPLineEnding::esSpikeArrow );
    CustomPlot->yAxis->setUpperEnding ( QCPLineEnding::esSpikeArrow );
    /*-----------------------设置横纵坐标-----------------------------*/
    CustomPlot->xAxis->setLabelColor ( Qt::green );//设置下标字体颜色
    CustomPlot->xAxis->setLabel ( QObject::tr ( "时间" ) );//设置下标文字
    CustomPlot->yAxis->setLabelColor ( QColor ( 255, 0, 0 ) );
    CustomPlot->yAxis->setLabel ( QObject::tr ( "压强(Pa)/流量(L/min)" ) );

    CustomPlot->yAxis->setRange ( -10, 200);//设置y坐标轴的大小范围
    CustomPlot->axisRect()->setupFullAxesBox();
    // make left and bottom axes transfer their ranges to right and top axes:
    connect(CustomPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), CustomPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(CustomPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), CustomPlot->yAxis2, SLOT(setRange(QCPRange)));

    /*-----------------------设置图例-----------------------------*/
    CustomPlot->legend->setVisible ( true );
    CustomPlot->legend->setFont ( QFont ( "Helvetica", 9 ) );
    // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
    CustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    if ( i == 0 ) {
        Pa_graph = CustomPlot->addGraph(); /* 显示压强曲线 */
        Spend_graph = CustomPlot->addGraph(); /* 显示流量曲线 */
        //QCPScatterStyle设置数据显示的形状，这里是圆形；QPen是数据外围的颜色和数据显示的大小；QBrush表示图例中数据内部的颜色和大小
        Pa_graph->setScatterStyle ( QCPScatterStyle ( QCPScatterStyle::ssCircle, QPen ( Qt::black, 1.5 ), QBrush ( Qt::green ), 9 ) );
        Pa_graph->setPen ( QPen ( QColor ( 255, 0, 0 ), 2 ) );//图例中连接数据曲线的颜色和大小
        Pa_graph->setName ( QObject::tr ( "氧气压强值" ) );//图例中数据的名称
        Spend_graph->setScatterStyle ( QCPScatterStyle ( QCPScatterStyle::ssSquare, QPen ( Qt::blue, 1.5 ), QBrush ( Qt::blue ), 9 ) );
        Spend_graph->setPen ( QPen ( QColor ( 0, 0, 255 ), 2 ) );
        Spend_graph->setName ( QObject::tr ( "氧气流量值" ) );
        i = 1;
        // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
       Pa_graph->rescaleAxes();
        Spend_graph->rescaleAxes();
    }
}

